﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Demo.Mmose.Core.Util;

namespace Demo.Mmose.Core.Common.Atom
{
    public class AtomicUlong : IAtomOperator<ulong>, IComparable, IComparable<AtomicUlong>
    {
        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        private AtomicUlong()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="atomicLong"></param>
        private AtomicUlong( ulong atomicLong )
        {
            m_AtomicLong = (long)atomicLong;
        }
        #endregion

        #region zh-CHS 属性 | en Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private long m_AtomicLong = 0;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public ulong Value
        {
            get { return (ulong)m_AtomicLong; }
        }
        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 以原子方式将给定值与当前值相加。
        /// </summary>
        /// <param name="addValue"></param>
        /// <returns></returns>
        public void Add( ulong addValue )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong + addValue;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将给定值与当前值相减。
        /// </summary>
        /// <param name="subtractValue"></param>
        /// <returns></returns>
        public void Subtract( ulong subtractValue )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong - subtractValue;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将给定值与当前值相乘。
        /// </summary>
        /// <param name="multiplyValue"></param>
        /// <returns></returns>
        public void Multiply( ulong multiplyValue )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong * multiplyValue;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将给定值与当前值相除。
        /// </summary>
        /// <param name="divideValue"></param>
        /// <returns></returns>
        public void Divide( ulong divideValue )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong / divideValue;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式设置为给定值。
        /// </summary>
        /// <param name="assignmentValue"></param>
        /// <returns></returns>
        public void Assignment( ulong assignmentValue )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = assignmentValue;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 如果当前值 == 预期值，则以原子方式将该值设置为给定的更新值。
        /// </summary>
        /// <param name="setValue"></param>
        /// <param name="compareValue"></param>
        /// <returns></returns>
        public bool CompareExchange( ulong setValue, ulong compareValue )
        {
            return Interlocked.CompareExchange( ref m_AtomicLong, (long)setValue, (long)compareValue ) == (long)compareValue;
        }

        /// <summary>
        /// 以原子方式将当前值减 1 ( -- )
        /// </summary>
        /// <returns></returns>
        public void Decrement()
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong - 1;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值加 1 ( ++ )
        /// </summary>
        /// <returns></returns>
        public void Increment()
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong + 1;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值左移 ( << )
        /// </summary>
        /// <returns></returns>
        public void LeftShift( int leftShift )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong << leftShift;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值右移 ( >> )
        /// </summary>
        /// <returns></returns>
        public void RightShift( int rightShift )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong >> rightShift;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值求正(一元操作) ( + )
        /// </summary>
        /// <param name="addValue"></param>
        /// <returns></returns>
        public void Plus()
        {
        }

        /// <summary>
        /// 以原子方式将当前值求负(一元操作) ( - )
        /// </summary>
        /// <param name="addValue"></param>
        /// <returns></returns>
        public void Minus()
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// 以原子方式将当前值取反(一元操作) ( ! )
        /// </summary>
        /// <param name="addValue"></param>
        /// <returns></returns>
        public void Invert()
        {
            throw new NotSupportedException();
        }

        /// <summary>
        /// 以原子方式将当前值求补 ( ~ )
        /// </summary>
        /// <returns></returns>
        public void OneComplement()
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = ~(ulong)m_AtomicLong;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值按位与 ( &= )
        /// </summary>
        /// <returns></returns>
        public void BitwiseAND( ulong bitwiseAnd )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong & bitwiseAnd;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值按位或 ( |= )
        /// </summary>
        /// <returns></returns>
        public void BitwiseInclusiveOR( ulong inclusiveOR )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong | inclusiveOR;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }

        /// <summary>
        /// 以原子方式将当前值按位异或 ( ^= )
        /// </summary>
        /// <returns></returns>
        public void BitwiseExclusiveOR( ulong exclusiveOR )
        {
            ulong oldAtomicUlong;
            ulong newAtomicUlong;

            do
            {
                oldAtomicUlong = (ulong)m_AtomicLong;
                newAtomicUlong = (ulong)m_AtomicLong ^ exclusiveOR;

            } while ( Interlocked.CompareExchange( ref m_AtomicLong, (long)newAtomicUlong, (long)oldAtomicUlong ) != (long)oldAtomicUlong );
        }
        #endregion

        #region zh-CHS 共有委托 | en Public Delegate
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<UpdatingValue<ulong>> m_EventUpdatingValue;
        /// <summary>
        /// 
        /// </summary>
        private SpinLock m_LockEventUpdating = new SpinLock();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<UpdatingValue<ulong>> UpdatingValue
        {
            add
            {
                SpinLockEx.ReliableEnter( ref m_LockEventUpdating );
                {
                    m_EventUpdatingValue += value;
                }
                m_LockEventUpdating.Exit();
            }
            remove
            {
                SpinLockEx.ReliableEnter( ref m_LockEventUpdating );
                {
                    m_EventUpdatingValue -= value;
                }
                m_LockEventUpdating.Exit();
            }
        }

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private EventHandler<UpdatedValue<ulong>> m_EventUpdatedValue;
        /// <summary>
        /// 
        /// </summary>
        private SpinLock m_LockEventUpdated = new SpinLock();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public event EventHandler<UpdatedValue<ulong>> UpdatedValue
        {
            add
            {
                SpinLockEx.ReliableEnter( ref m_LockEventUpdated );
                {
                    m_EventUpdatedValue += value;
                }
                m_LockEventUpdated.Exit();
            }
            remove
            {
                SpinLockEx.ReliableEnter( ref m_LockEventUpdated );
                {
                    m_EventUpdatedValue -= value;
                }
                m_LockEventUpdated.Exit();
            }
        }
        #endregion

        #region zh-CHS 方法 | en Method
        /// <summary>
        /// 将当前值左移 ( << )，并返回左移后的数据
        /// </summary>
        /// <param name="atomicIntA"></param>
        /// <param name="atomicIntB"></param>
        /// <returns></returns>
        public static AtomicUlong operator >>( AtomicUlong atomicLongA, int atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong >> atomicLongB );
        }

        /// <summary>
        /// 将当前值右移 ( >> )，并返回右移后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator <<( AtomicUlong atomicLongA, int atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong << atomicLongB );
        }

        /// <summary>
        /// 将给定值与当前值相加，并返回相加后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator +( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong + atomicLongB );
        }

        /// <summary>
        /// 将给定值与当前值相加，并返回相加后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator +( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong + (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将给定值与当前值相减，并返回相减后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator -( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong - atomicLongB );
        }

        /// <summary>
        /// 将给定值与当前值相减，并返回相减后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator -( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong - (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将给定值与当前值相乘，并返回相乘后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator *( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong * atomicLongB );
        }

        /// <summary>
        /// 将给定值与当前值相乘，并返回相乘后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator *( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong * (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值与给定值相除，并返回相除后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator /( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong / atomicLongB );
        }

        /// <summary>
        /// 将当前值与给定值相除，并返回相除后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator /( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong / (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值与给定值相模，并返回相模后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator %( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong % atomicLongB );
        }

        /// <summary>
        /// 将当前值与给定值相模，并返回相模后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator %( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong % (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值与给定值相与，并返回相与后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator &( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong & atomicLongB );
        }

        /// <summary>
        /// 将当前值与给定值相与，并返回相与后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator &( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong & (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值与给定值相或，并返回相或后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator |( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong | atomicLongB );
        }

        /// <summary>
        /// 将当前值与给定值相或，并返回相或后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator |( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong | (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值与给定值相异或，并返回相异或后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator ^( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong ^ atomicLongB );
        }

        /// <summary>
        /// 将当前值与给定值相异或，并返回相异或后的数据
        /// </summary>
        /// <param name="atomicLongA"></param>
        /// <param name="atomicLongB"></param>
        /// <returns></returns>
        public static AtomicUlong operator ^( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return new AtomicUlong( (ulong)atomicLongA.m_AtomicLong ^ (ulong)atomicLongB.m_AtomicLong );
        }

        /// <summary>
        /// 将当前值求补，并返回求补后的数据
        /// </summary>
        /// <param name="atomicIntA"></param>
        /// <returns></returns>
        public static AtomicUlong operator ~( AtomicUlong atomicLong )
        {
            return new AtomicUlong( ~(ulong)atomicLong.m_AtomicLong );
        }

        /// <summary>
        /// 以原子方式将当前值加 1 ( ++ )
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static AtomicUlong operator ++( AtomicUlong atomicLong )
        {
            atomicLong.Increment();

            return atomicLong;
        }

        /// <summary>
        /// 以原子方式将当前值减 1 ( -- )
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static AtomicUlong operator --( AtomicUlong atomicLong )
        {
            atomicLong.Decrement();

            return atomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator ==( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong == (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator ==( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong == atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator !=( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong != (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator !=( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong != atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong < (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong < atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator >( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong > (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator >( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong > atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <=( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong <= (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator <=( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong <= atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator >=( AtomicUlong atomicLongA, AtomicUlong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong >= (ulong)atomicLongB.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="l"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool operator >=( AtomicUlong atomicLongA, ulong atomicLongB )
        {
            return (ulong)atomicLongA.m_AtomicLong >= atomicLongB;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="iSerial"></param>
        /// <returns></returns>
        public static explicit operator ulong( AtomicUlong atomicLong )
        {
            return (ulong)atomicLong.m_AtomicLong;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="atomicLong"></param>
        /// <returns></returns>
        public static implicit operator AtomicUlong( ulong atomicLong )
        {
            return new AtomicUlong( atomicLong );
        }
        #endregion

        #region zh-CHS 方法覆盖 | en Method Overrides
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_AtomicLong.ToString();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            return m_AtomicLong.GetHashCode();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xObject"></param>
        /// <returns></returns>
        public override bool Equals( object xObject )
        {
            AtomicUlong atomicLong = xObject as AtomicUlong;
            if ( atomicLong == null )
                return false;

            return (ulong)atomicLong.m_AtomicLong == (ulong)m_AtomicLong;
        }
        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <param name="otherAtomicInt"></param>
        /// <returns></returns>
        public int CompareTo( AtomicUlong otherAtomicLong )
        {
            return ( (ulong)m_AtomicLong ).CompareTo( (ulong)otherAtomicLong.m_AtomicLong );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="otherObject"></param>
        /// <returns></returns>
        public int CompareTo( object otherObject )
        {
            AtomicUlong atomicLong = otherObject as AtomicUlong;
            if ( atomicLong == null )
                return 1;
            else
                return CompareTo( atomicLong );
        }
        #endregion
    }
}
